﻿using System.Globalization;
using System.Windows.Controls;

namespace WpfApp16
{
    public class IntValidationRule : ValidationRule
    {
        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            if (value == null || string.IsNullOrWhiteSpace(value.ToString()))
                return new ValidationResult(false, "请输入数字");

            double number;
            if (!double.TryParse(value.ToString(), out number))
                return new ValidationResult(false, "必须为数字");

            return ValidationResult.ValidResult;
        }
    }

    public class FloatValidationRule : ValidationRule
    {
        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            if (value == null || string.IsNullOrWhiteSpace(value.ToString()))
                return new ValidationResult(false, "请输入数字");

            double number;
            if (!double.TryParse(value.ToString(), out number))
                return new ValidationResult(false, "必须为数字");

            return ValidationResult.ValidResult;
        }
    }
    public class DoubleValidationRule : ValidationRule
    {
        public override ValidationResult Validate(object value, CultureInfo cultureInfo)
        {
            if (value == null || string.IsNullOrWhiteSpace(value.ToString()))
                return new ValidationResult(false, "请输入数字");

            double number;
            if (!double.TryParse(value.ToString(), out number))
                return new ValidationResult(false, "必须为数字");

            return ValidationResult.ValidResult;
        }
    }
}

